//
//  SectionHeadTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/4/7.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "SectionHeadTableViewCell.h"

@interface SectionHeadTableViewCell ()

@property (nonatomic,copy)clickBlock block;

//@property (nonatomic,strong)FoldModel* model;

@property(nonatomic,strong)UILabel *headLabel;

@property(nonatomic,strong)UIButton *isAllSelectBtn;

@property(nonatomic,strong)UIButton *isOpenBtn;

@end

@implementation SectionHeadTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.isAllSelectBtn.hidden=NO;

        self.isOpenBtn.hidden=NO;

        self.headLabel.font=Font_Number(18);

        self.backgroundColor=WhiteColor;
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
}

// isOpenBtn
-(UIButton *)isOpenBtn
{
    if (!_isOpenBtn) {
        _isOpenBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"openIcon"] andWithSelectImage:[UIImage imageNamed:@"openIcon"] andWithBtnAction:^{
        }];
        [self.contentView addSubview:_isOpenBtn];
        self.isOpenBtn.tag=998;
//        _isOpenBtn.backgroundColor=[UIColor redColor];
        self.isOpenBtn.userInteractionEnabled=NO;
        [_isOpenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.centerY.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(kmargin*3,kmargin*3));
        }];
    }
    return _isOpenBtn;
}

-(void)isAllSelectBtnEvent:(UIButton *)sender
{
    sender.selected=!sender.selected;

    if (self.block) {
        self.block(self ,self.model,sender.selected);
    }
}

// isAllSelectBtn
-(UIButton *)isAllSelectBtn
{
    if (!_isAllSelectBtn) {
        _isAllSelectBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"no_selectIcon"] andWithSelectImage:[UIImage imageNamed:@"selectIcon"] andWithBtnAction:^{
            [self isAllSelectBtnEvent:self.isAllSelectBtn];
        }];
        self.isAllSelectBtn.tag=999;
        [self.contentView addSubview:self.isAllSelectBtn];
//        _isAllSelectBtn.backgroundColor=MainColor;
        [_isAllSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.isOpenBtn.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(kmargin*2,kmargin*2));
        }];
    }
    return _isAllSelectBtn;
}

// headLabel
- (UILabel *)headLabel
{
    if (!_headLabel) {
        _headLabel=[self getLabelWithText:@"组头名" font:Font_Number(18) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_headLabel];
        [_headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.left.mas_equalTo(self.isAllSelectBtn.mas_right).offset(kmargin);
        }];
    }
    return _headLabel;
}

- (void)configModel:(FoldModel *)model andBlock:(clickBlock)block
{
    self.block = block;
    self.model = model;
    self.headLabel.text = model.group_name;
}

@end
